﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body>

<?php

include("inc/joomlaInt.php");
include("inc/inc_configuration.php");

if ($jUser==0)
{
	echo "Bitte zuerst einloggen!";
}
else
{

	$matchday = $_GET["matchday"];
	$liga = $_GET["liga"];

	if ($matchday=="")
	{
		$matchday=1;
	}


	$lq = "SELECT * FROM $tbl_lt WHERE leagueId=$liga";
	$lqe = mysql_query($lq);
	$lqc = mysql_num_rows($lqe);

	$mAnz = ($lqc-1)*2;

	$sQ="SELECT * FROM $tbl_matches WHERE matchday=$matchday AND leagueId=$liga";
	$sQe=mysql_query($sQ);

	$count=1;
	if ($mAnz>0)
	{
		echo "<table id='tborder' bgcolor='#DADADA'><thead id='tabelle'><tr><center><th colspan='8'>";
	}

	echo "	";
			
	for($count = 1; $count < $mAnz+1; $count++)
	{
		echo " <a href='spiele_spieltag.php?matchday=$count&liga=$liga'>$count</a> ";
	}

	if ($mAnz>0)
	{
		echo "</center></th></tr></thead>";
	}

	while ($row = mysql_fetch_object($sQe))
	{
		$mI=$row->id;
		$homeT=$row->homeT;
		$guestT=$row->guestT;
		$hG=$row->homeG;
		$gG=$row->guestG;
		$f=$row->free;
		$hC=$row->homeC;
		$gC=$row->guestC;
		
		$b="";
		
		if ($f==3)
		{
			$b="<a href='spielbericht.php?matchID=$mI&type=2'><img src='img/bericht.png' alt='Spielbericht'></a>";
		}
		
		if ($hG=="")
		{
			$hG="-";
			$gG="-";
			$b="";
		}
		
		
		$tHq="SELECT name FROM $tbl_teams t WHERE t.id=$homeT";
		$tGq="SELECT name FROM $tbl_teams t WHERE t.id=$guestT";
		$tHqe = mysql_query($tHq);
		$tGqe = mysql_query($tGq);
		$tHn = mysql_fetch_object($tHqe)->name;
		$tGn = mysql_fetch_object($tGqe)->name;
		
		if ($f==1)
		{
		
			$uHSql="	SELECT u.username AS uHn, c.id AS hC, u.id AS uid FROM $tbl_combinations c, $tbl_users u
						WHERE
						(c.teamId=$homeT) AND
						(c.active=1) AND
						(c.userId=u.id)";
			$uGSql="	SELECT u.username AS uGn, c.id AS gC, u.id AS uid FROM $tbl_combinations c, $tbl_users u
						WHERE
						(c.teamId=$guestT) AND
						(c.active=1) AND
						(c.userId=u.id)";
			
			$uHq = mysql_query($uHSql);
			$uGq = mysql_query($uGSql);
			
			$uHqo=mysql_fetch_object($uHq);
			$uGqo=mysql_fetch_object($uGq);
			
			$uHn = $uHqo->uHn;
			$uGn = $uGqo->uGn;
			
			$uHi = $uHqo->uid;
			$uGi = $uGqo->uid;
			
			if ($uHn=="")
			{
				$uHn = "(-)";
			}
			else
			{
				$uHn="<a href='profil.php?id=$uHi'>$uHn</a>";
			}
			
			if ($uGn=="")
			{
				$uGn = "(-)";
			}
			else
			{
				$uGn="<a href='profil.php?id=$uGi'>$uGn</a>";
			}
		}
		else
		{
			if ($f>=2)
			{
				$cHi=$hC;
				$cGi=$gC;
				
				if ($f==3)
				{
					$b="<a href='spielbericht.php?matchID=$mId&type=2'><img src='img/bericht.png' alt='Spielbericht'></a>";
				}
				
				$uHSql="	SELECT username, u.id AS uid FROM $tbl_combinations c, $tbl_users u
									WHERE
									(c.id=$cHi) AND
									(c.userId=u.id)";
				$uGSql="	SELECT username, u.id AS uid FROM $tbl_combinations c, $tbl_users u
									WHERE
									(c.id=$cGi) AND
									(c.userId=u.id)";
									
				if ($f==3 OR $f==2)
				{
					
								
					$uHq = mysql_query($uHSql);
					$uGq = mysql_query($uGSql);
					
					$uHnq = mysql_fetch_object($uHq);
					$uHn = $uHnq->username;
					$uHi = $uHnq->uid;
					$uHn = "<a href='profil.php?id=$uHi'>$uHn</a>";
					
					$uGnq = mysql_fetch_object($uGq);
					$uGn = $uGnq->username;
					$uGi = $uGnq->uid;
					$uGn = "<a href='profil.php?id=$uGi'>$uGn</a>";
				}
				else
				{
					if ($cHi==0)
					{
						$uHn="Gewertet";
					}
					else
					{
						$uHq = mysql_query($uHSql);
						$uHnq = mysql_fetch_object($uHq);
						$uHn = $uHnq->username;
						$uHi = $uHnq->uid;
						$uHn = "<a href='profil.php?id=$uHi'>$uHn</a>";
					}
					
					if ($cGi==0)
					{
						$uGn="Gewertet";
					}
					else
					{
						$uGq = mysql_query($uGSql);
						$uGnq = mysql_fetch_object($uGq);
						$uGn = $uGnq->username;
						$uGi = $uGnq->uid;
						$uGn = "<a href='profil.php?id=$uGi'>$uGn</a>";
					}
				}
			}
		}
		

			
		echo"<tr>	<td width='44%'><center><a href='spiele_team.php?team=$homeT&liga=$liga'>$tHn</a><br>$uHn</td>
					<td><a href='team_kader.php?team=$homeT'><img src='img/logos/",$row->homeT,".png' width='35' height='35' alt=''></a></td>
					<td width='3%'><center>$hG</center></td>
					<td width='2%'><center>:</center></td>
					<td width='3%'><center>$gG</center></td>
					<td><a href='team_kader.php?team=$guestT'><img src='img/logos/",$row->guestT,".png' width='35' height='35' alt=''></a></td>
					<td width='44%'><center><a href='spiele_team.php?team=$guestT&liga=$liga'>$tGn</a><br>$uGn</center></td>
					<td width='4%'><center>$b</center></td>
			</tr>";
	}

		echo "	<thead id='tabelle'><tr>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
						<th></th>
					</tr>
			</thead>";

	echo "</table><br><br>";

	include("inc/inc_tabelle.php");



	echo "<br><br>
				<center><a href='lima.php' class='button zurueck'>Zurück</a></center>";

}
?>

</body>
</html>